﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Microsoft.Reporting.WinForms;
using DataLayer;


namespace WinProgProject2
{
    public partial class RaporGoruntuleme : Form
    {
        ErrorLogService.Service1Client sv = new ErrorLogService.Service1Client();
        public RaporGoruntuleme()
        {
            InitializeComponent();
        }

        private void RaporGoruntuleme_Load(object sender, EventArgs e)
        {
            backgroundWorker1.RunWorkerAsync();
            
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                backgroundWorker1.ReportProgress(0,new object[] {"Servise bağlanıyor...",null});
                RaporServisiReferans.RaporServisiClient svc = new RaporServisiReferans.RaporServisiClient();

                this.GecerliRezervasyonBilgileriBindingSource.DataSource = svc.GecerliRezervasyonRaporuGetir();


                if (this.GecerliRezervasyonBilgileriBindingSource == null)
                    backgroundWorker1.ReportProgress(0, new object[] {"Geçerli rezervasyon bilgileri çekilemedi.",null});

                backgroundWorker1.ReportProgress(25, new object[] {"Servise bağlanıyor...",rvRapor});
                Thread.Sleep(1000);
                //this.rvRapor.RefreshReport();

                this.MusteriRezervasyonMiktarlariBindingSource.DataSource = svc.MusteriRezervasyonMiktarlariRaporuGetir();

                if (this.MusteriRezervasyonMiktarlariBindingSource == null)
                    backgroundWorker1.ReportProgress(25, new object [] {"Müşteri rezervasyon miktarlari çekilemedi.",null});
                

                backgroundWorker1.ReportProgress(50, new object [] {"Servise bağlanıyor...",rvRaporMusteri});
                Thread.Sleep(1000);
                
                //this.rvRaporMusteri.RefreshReport();



                this.MasaTipiRezervasyonMiktarlariniCek_ResultBindingSource.DataSource = svc.MasaTipiRezervasyonMiktarlariGetir();

                if (this.MasaTipiRezervasyonMiktarlariniCek_ResultBindingSource == null)
                    backgroundWorker1.ReportProgress(50, new object [] {"Müşteri rezervasyon miktarlari çekilemedi.",null});

                backgroundWorker1.ReportProgress(75, new object[] {"Servise bağlanıyor...",rvMasaTipi});

                //this.rvMasaTipi.RefreshReport();

                backgroundWorker1.ReportProgress(100, new object[] {"Servise bağlanıyor...",null});
                Thread.Sleep(1000);

                svc.Close();
                
            }
            catch (Exception ex)
            {
                backgroundWorker1.ReportProgress(0,ex.Message);
                sv.errorEkle(Session.kullaniciKodu, ex.Message, 6, "Rapor Görüntüleme İşlemleri");
            }
        }

        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            
            object[] o = e.UserState as object[];

            try
            {
                if (o[1] != null)
                    (o[1] as ReportViewer).RefreshReport();




                yuklenmeStatus.Text = o[0] as string;
                yuklenmeProgress.Value = e.ProgressPercentage;

            }
            catch (NullReferenceException n)
            {
                sv.errorEkle(Session.kullaniciKodu, n.Message, 6, "Rapor Görüntüleme İşlemleri/Background Worker");
            }
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            yuklenmeStatus.Text = "Hazır";
            yuklenmeProgress.Value = 0;
        }


    }
}
